package com.fenghongzhang.day0122;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    private MyReceiver2 myReceiver2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //动态方法注册一个广播接收者
//         myReceiver2 = new MyReceiver2();
//        IntentFilter intentFilter = new IntentFilter();
//        intentFilter.addAction("com.feng.1803");
//
//        registerReceiver(myReceiver2,intentFilter);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(myReceiver2);
    }

    /**
     * 1, 发送者.
     * 2, 频道
     * 3, 接收者.-频道一样.
     *
     * 给接收者加频道, 就是接收者两种注册方式,
     * 频道加到清单文件,就是静态.
     * 在代码里加频道就是 动态.
     * @param view
     */
    public void send(View view) {

        Intent intent = new Intent();
        intent.setAction("com.feng.1803");


        Bundle bundle = new Bundle();
        bundle.putString("name","小白");

        intent.putExtras(bundle);

        //发送一个广播
//        sendBroadcast(intent); //发走了

        //发送有序的广播
        sendOrderedBroadcast(intent,null);
    }


}
